Skip to content

Fix validation error when pausing broadcast during live streaming#20

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-19
Draft

Fix validation error when pausing broadcast during live streaming#20
Copilot wants to merge 2 commits intomainfrom
copilot/fix-19

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 7, 2025

When a broadcast is paused or stopped while live streaming is active, the application throws a Convex validation error:

ArgumentValidationError: Value does not match validator.
Path: .session_id
Value: null
Validator: v.string()

This error occurs due to a race condition in the HostAgentService. When the stop() method is called, it asynchronously ends the session and sets this.currentSessionId = null. However, ongoing async operations like saveNarrationToDatabase() may still be running and attempt to call incrementHostSessionStats with the now-null session ID.

Root Cause

The issue happens in this sequence:

  1. Live streaming is active with narrations being processed
  2. User pauses/stops the broadcast
  3. stop() method calls endSession() which sets this.currentSessionId = null
  4. Meanwhile, saveNarrationToDatabase() is still executing async operations
  5. When it reaches the incrementHostSessionStats call, it passes null instead of a valid session ID

Solution

Store the session ID in a local variable at the beginning of the saveNarrationToDatabase method to prevent race conditions. This ensures all database operations within the method use the same valid session ID that was active when the method started.

Changes made:

  • Added const sessionId = this.currentSessionId after the initial null check
  • Updated all database mutation calls to use the local sessionId instead of this.currentSessionId
  • This prevents the validation error while maintaining all existing functionality

The fix is minimal and surgical, addressing only the specific race condition without affecting any other parts of the system.

Fixes #19.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Store session ID locally to prevent race conditions during async operations
- Prevents null session_id being passed to incrementHostSessionStats when broadcast is paused/stopped

Co-authored-by: acdc-digital <127530566+acdc-digital@users.noreply.github.com>
Copilot AI changed the title [WIP] Pause/ Stop Broadcast Validation Error Fix validation error when pausing broadcast during live streaming Sep 7, 2025
Copilot AI requested a review from acdc-digital September 7, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pause/ Stop Broadcast Validation Error

2 participants